package com.ruoyi.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.domain.ParkingWhite;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.ParkingBlack;
import com.ruoyi.service.IParkingBlackService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 黑名单Controller
 * 
 * @author ruoyi
 * @date 2025-11-04
 */
@RestController
@RequestMapping("/parking/black")
public class ParkingBlackController extends BaseController
{
    @Autowired
    private IParkingBlackService parkingBlackService;

    /**
     * 查询黑名单列表
     */
    @PreAuthorize("@ss.hasPermi('parking:black:list')")
    @GetMapping("/list")
    public TableDataInfo list(ParkingBlack parkingBlack)
    {
        startPage();
        List<ParkingBlack> list = parkingBlackService.selectParkingBlackList(parkingBlack);
        return getDataTable(list);
    }

    /**
     * 导出黑名单列表
     */
    @PreAuthorize("@ss.hasPermi('parking:black:export')")
    @Log(title = "黑名单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkingBlack parkingBlack)
    {
        List<ParkingBlack> list = parkingBlackService.selectParkingBlackList(parkingBlack);
        ExcelUtil<ParkingBlack> util = new ExcelUtil<ParkingBlack>(ParkingBlack.class);
        util.exportExcel(response, list, "黑名单数据");
    }

    /**
     * 获取黑名单详细信息
     */
    @PreAuthorize("@ss.hasPermi('parking:black:query')")
    @GetMapping(value = "/{blackId}")
    public AjaxResult getInfo(@PathVariable("blackId") Long blackId)
    {
        return success(parkingBlackService.selectParkingBlackByBlackId(blackId));
    }

    /**
     * 新增黑名单
     */
    @PreAuthorize("@ss.hasPermi('parking:black:add')")
    @Log(title = "黑名单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkingBlack parkingBlack)
    {
        return toAjax(parkingBlackService.insertParkingBlack(parkingBlack));
    }

    /**
     * 修改黑名单
     */
    @PreAuthorize("@ss.hasPermi('parking:black:edit')")
    @Log(title = "黑名单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkingBlack parkingBlack)
    {
        return toAjax(parkingBlackService.updateParkingBlack(parkingBlack));
    }

    /**
     * 删除黑名单
     */
    @PreAuthorize("@ss.hasPermi('parking:black:remove')")
    @Log(title = "黑名单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{blackIds}")
    public AjaxResult remove(@PathVariable Long[] blackIds)
    {
        return toAjax(parkingBlackService.deleteParkingBlackByBlackId(blackIds[0]));
    }
    @Log(title = "黑名单", businessType = BusinessType.UPDATE)
    @PutMapping("/resend/{blackId}")
    public AjaxResult resend(@PathVariable Long blackId){
        ParkingBlack parkingBlack = parkingBlackService.selectParkingBlackByBlackId(blackId);
        return toAjax(parkingBlackService.sendRequest(parkingBlack));
    }
}
